﻿#region

using SqlSugar;
using Vin.Extension.Framework.Entities;
using Vin.Extension.SqlSugar.Attributes;

#endregion

namespace Vin.Extension.Framework.Monitor.Entities;

public enum OperationStatus
{
    None = 0,

    /// <summary>
    /// 成功
    /// </summary>
    Success = 1,

    /// <summary>
    /// 失败
    /// </summary>
    Fail = 2,

    /// <summary>
    /// 异常
    /// </summary>
    Exception = 3
}

/// <summary>
/// 操作日志
/// </summary>
[SugarIndex("index_{table}_createTime", nameof(CreateTime), OrderByType.Asc)]
[VinSqlSugarEntity("操作日志")]
public class SysOperateLog : VinFrameworkBaseEntity
{
    /// <summary>
    /// 操作模块
    /// </summary>
    [SugarColumn(ColumnDescription = "操作模块")]
    public string? Title { get; set; }

    /// <summary>
    /// 操作类型
    /// </summary>
    [SugarColumn(ColumnDescription = "操作类型")]
    public int? BusinessType { get; set; }

    /// <summary>
    /// 控制器地址
    /// </summary>
    [SugarColumn(ColumnDescription = "控制器地址", DefaultValue = "''")]
    public string? ControllerPath { get; set; }

    /// <summary>
    /// Action地址
    /// </summary>
    [SugarColumn(ColumnDescription = "Action地址", DefaultValue = "''")]
    public string? ActionPath { get; set; }

    /// <summary>
    /// 请求地址
    /// </summary>
    [SugarColumn(ColumnDescription = "请求地址")]
    public string? RequestUrl { get; set; }

    /// <summary>
    /// 请求方法
    /// </summary>
    [SugarColumn(ColumnDescription = "请求方法")]
    public string? RequestMethod { get; set; }

    /// <summary>
    /// 请求参数
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "请求参数")]
    public object? RequestParams { get; set; }

    /// <summary>
    /// 请求体
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "请求体")]
    public object? RequestBody { get; set; }

    /// <summary>
    /// 请求头
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "请求头")]
    public object? RequestHeader { get; set; }

    /// <summary>
    /// 请求用户信息
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "请求用户信息")]
    public object? RequestUser { get; set; }

    /// <summary>
    /// 请求用户名称
    /// </summary>
    [SugarColumn(DefaultValue = "''", ColumnDescription = "请求用户名称")]
    public string? RequestUserName { get; set; }

    /// <summary>
    /// 请求用户ID
    /// </summary>
    [SugarColumn(DefaultValue = "0", ColumnDescription = "请求用户ID")]
    public long? RequestUserId { get; set; }

    /// <summary>
    /// 请求curl
    /// </summary>
    [SugarColumn(ColumnDataType = "longtext", ColumnDescription = "请求curl")]
    public string? RequestCurl { get; set; }

    /// <summary>
    /// 响应码
    /// </summary>
    [SugarColumn(DefaultValue = "0", ColumnDescription = "响应码")]
    public int? ResponseCode { get; set; }

    /// <summary>
    /// 响应体
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "响应体")]
    public object? ResponseBody { get; set; }

    /// <summary>
    /// 异常信息
    /// </summary>
    [SugarColumn(ColumnDataType = "text", ColumnDescription = "异常信息")]
    public string? Exception { get; set; }

    /// <summary>
    /// 执行的SQL
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "执行的SQL")]
    public object? Sql { get; set; }

    /// <summary>
    /// 请求ip
    /// </summary>
    [SugarColumn(DefaultValue = "''", ColumnDescription = "请求ip")]
    public string? Ip { get; set; }

    /// <summary>
    /// 请求位置
    /// </summary>
    [SugarColumn(DefaultValue = "''", ColumnDescription = "请求位置")]
    public string? Location { get; set; }

    /// <summary>
    /// 请求浏览器
    /// </summary>
    [SugarColumn(DefaultValue = "''", ColumnDescription = "请求浏览器")]
    public string? Browser { get; set; }

    /// <summary>
    /// 请求操作系统
    /// </summary>
    [SugarColumn(DefaultValue = "''", ColumnDescription = "请求操作系统")]
    public string? Os { get; set; }

    /// <summary>
    /// 请求代理
    /// </summary>
    [SugarColumn(ColumnDataType = "text", ColumnDescription = "请求代理")]
    public string? UserAgent { get; set; }

    /// <summary>
    /// 设备
    /// </summary>
    [SugarColumn(DefaultValue = "''", ColumnDescription = "设备")]
    public string? Device { get; set; }

    /// <summary>
    /// 操作状态
    /// </summary>
    [SugarColumn(ColumnDescription = "操作状态")]
    public OperationStatus? Status { get; set; }

    /// <summary>
    /// 消耗时间
    /// </summary>
    [SugarColumn(ColumnDescription = "消耗时间")]
    public long? CostTime { get; set; }

    /// <summary>
    /// 自定义消息
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, ColumnDescription = "自定义消息")]
    public List<string>? CustomMsg { get; set; }
}